package com.leo;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleSetProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableSet;
import javafx.collections.SetChangeListener;
import javafx.stage.Stage;

/**
 * @ClassName SetPropertyDemo
 * @Description 去重
 * @Author wangss
 * @date 2020.05.28 23:05
 * @Version 1.0
 */
public class SetPropertyDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        ObservableSet<String> set = FXCollections.observableSet();
        set.add("A");
        set.add("B");
        set.add("C");

        SimpleSetProperty<String> setProperty = new SimpleSetProperty<>(set);

        setProperty.addListener((observable, oldValue, newValue) -> {
            newValue.forEach(System.out::println);
        });

        setProperty.addListener(new SetChangeListener<String>() {
            @Override
            public void onChanged(Change<? extends String> change) {

            }
        });

        set.add("D");

        Platform.exit();
    }
}
